## This file is a quick tutorial on writing CMakeLists for targeting the Vita
cmake_minimum_required(VERSION 3.2)

## This includes the Vita toolchain, must go before project definition
# It is a convenience so you do not have to type
# -DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake for cmake. It is
# highly recommended that you include this block for all projects.
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
  if(DEFINED ENV{VITASDK})
    set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")
  else()
    message(FATAL_ERROR "Please define VITASDK to point to your SDK path!")
  endif()
endif()

## Define project parameters here
# Name of the project
project(Gnash C CXX)
# This line adds Vita helper macros, must go after project definition in order
# to build Vita specific artifacts (self/vpk).
include("${VITASDK}/share/vita.cmake" REQUIRED)
#include("${VITASDK}/share/vita.cmake" REQUIRED)

## Configuration options for this app
# Display name (under bubble in LiveArea)
set(VITA_APP_NAME "Gnash")
# Unique ID must be exactly 9 characters. Recommended: XXXXYYYYY where X =
# unique string of developer and Y = a unique number for this app
set(VITA_TITLEID  "GNASHPLAY")
set(VITA_VPKNAME "GnashPlay")
# Optional version string to show in LiveArea's more info screen
set(VITA_VERSION  "00.10")

set(DATA_PATH "ux0:data/" CACHE STRING "Path to data (with trailing /)")

add_definitions(-DDATA_PATH="${DATA_PATH}")
add_definitions(-DHAVE_GLES1_EGL_H)
add_definitions(-DGUI_SDL)
add_definitions(-DBUILD_EGL_DEVICE)
add_definitions(-DRENDERER_AGG)
add_definitions(-DHAVE_CONFIG_H)
add_definitions(-D_DEBUG)

add_definitions(-DHAVE_EGL_EGL_H)
#add_definitions(-DDREAMCAST)
add_definitions(-DSYSCONFDIR="")
add_definitions(-DFF_INPUT_BUFFER_PADDING_SIZE=0)
add_definitions(-DPLUGINSDIR="")
add_definitions(-DPIXELFORMAT_RGB565)

## Flags and includes for building
# Note that we make sure not to overwrite previous flags
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-q -O3 -g -ffast-math -mfloat-abi=softfp -Wno-deprecated")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=gnu++20 -Wno-write-strings -Wno-psabi -Wno-error=register")

# Optional. You can specify more param.sfo flags this way.
set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d PARENTAL_LEVEL=1")

# Add any additional library paths here
# ${CMAKE_CURRENT_BINARY_DIR} lets you use any library currently being built
link_directories(
  ${CMAKE_CURRENT_BINARY_DIR}
)


file(GLOB AGG "agg/*.cpp")
file(GLOB AGGSRC "agg/src/*.cpp")
file(GLOB AGGSRCCTRL "agg/src/ctrl/*.cpp")
file(GLOB AGGSRCPLATFORM "agg/src/ctrl/platform/*.cpp")
file(GLOB GUISDLAGG "gui/sdl/agg/*.cpp")
file(GLOB GUISDL "gui/sdl/*.cpp")
file(GLOB GUI "gui/*.cpp")

file(GLOB BASE "libbase/*.cpp")
file(GLOB CORE "libcore/*.cpp")
file(GLOB COREABC "libcore/abc/*.cpp")
file(GLOB COREABCUNUSED "libcore/abc/unused/*.cpp")
file(GLOB asobj "libcore/asobj/*.cpp")
file(GLOB asobjflash "libcore/asobj/flash/*.cpp")
file(GLOB asobjflashd "libcore/asobj/flash/display/*.cpp")
file(GLOB asobjflashe "libcore/asobj/flash/external/*.cpp")
file(GLOB asobjflashf "libcore/asobj/flash/filters/*.cpp")
file(GLOB asobjflashg "libcore/asobj/flash/geom/*.cpp")
file(GLOB asobjflashn "libcore/asobj/flash/net/*.cpp")
file(GLOB asobjflasht "libcore/asobj/flash/text/*.cpp")

file(GLOB parser "libcore/parser/*.cpp")
file(GLOB swf "libcore/swf/*.cpp")
file(GLOB vm "libcore/vm/*.cpp")

file(GLOB DEVICE "libdevice/*.cpp")
file(GLOB DEVICEEGL "libdevice/egl/*.cpp")
file(GLOB DEVICEEGLREIMPL "libdevice/reimpl/*.c")

file(GLOB MEDIA "libmedia/*.cpp")
file(GLOB MEDIAFFMPEG "libmedia/ffmpeg/*.cpp")

file(GLOB RENDER "librender/*.cpp")
file(GLOB RENDERAGG "librender/agg/*.cpp")

file(GLOB RENDEROPENGLES "librender/opengles1/*.cpp")
file(GLOB SOUND "libsound/*.cpp")
file(GLOB SOUNDSDL "libsound/sdl/*.cpp")


## Build and link
# Add all the files needed to compile here
add_executable(${PROJECT_NAME}.elf
               ${DEVICE}
               ${DEVICEEGL}

               ${DEVICEEGLREIMPL}
               ${AGG}
               ${AGGSRC}
               ${AGGSRCCTRL}
               ${AGGSRCPLATFORM}
               ${GUISDLAGG}
               ${GUISDL}
               ${GUI}
			   
			         ${BASE}
               ${CORE}
               ${COREABC}
               #${COREABCUNUSED}

               ${asobj}
               ${asobjflash}
               ${asobjflashd}
               ${asobjflashe}
               ${asobjflashf}
               ${asobjflashg}
               ${asobjflashn}
               ${asobjflasht}
			   
               ${parser}
               ${swf}
               ${vm}
			   
               ${MEDIA}
               ${MEDIAFFMPEG}
			   
               ${RENDER}
               ${RENDERAGG}
               #${RENDEROPENGLES}

               ${SOUND}
               ${SOUNDSDL}
)

target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/agg/include
                           )
						   
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/gui
                           )

                           target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}
                           )      

                           target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/gui/sdl
                           )
                           target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/gui/sdl/agg
                           )
                           target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libbase
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/abc
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/asobj
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/parser
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/swf
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/vm
                           )
                           target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/asobj/flash
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/asobj/flash/display
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/asobj/flash/external
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/asobj/flash/filters
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/asobj/flash/geom
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/asobj/flash/net
                           )
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libcore/asobj/flash/text
                           )
						   
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libdevice/egl
                           )

						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libdevice
                           )
						   
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libmedia
                           )
                           target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libmedia/ffmpeg
                           )
						   
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/librender
                           )
						   
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/librender/agg
                           )
						   
						   target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libsound
                           )
						   
						    target_include_directories(${CMAKE_PROJECT_NAME}.elf
                           PUBLIC ${CMAKE_SOURCE_DIR}/libsound/sdl
                           )

                target_include_directories(${CMAKE_PROJECT_NAME}.elf
  PUBLIC ${VITASDK}/arm-vita-eabi/include/freetype2
                )

# Library to link to (drop the -l prefix). This will mostly be stubs.
target_link_libraries(${PROJECT_NAME}.elf
  -Wl,--whole-archive pthread -Wl,--no-whole-archive
  SceLibKernel_stub # this line is only for demonstration. It's not needed as
                    # the most common stubs are automatically included.
  SceDisplay_stub   # This used by debugScreenPrintf()
  SceDisplay_stub_weak
  stdc++
  vitaGL
                      vitashark
                      SceShaccCgExt
                      taihen_stub
                      SceShaccCg_stub
                      jpeg
                      openAl
                      z
                      m
                      bz2
                      png16
                      freetype
                      mathneon
                      SceAppMgr_stub
                      SceAudio_stub
                      SceAudioIn_stub
                      SceCtrl_stub
                      SceCommonDialog_stub
                      SceDisplay_stub
                      SceKernelDmacMgr_stub
                      SceGxm_stub
                      SceShaccCg_stub
                      SceSysmodule_stub
                      ScePower_stub
                      SceTouch_stub
                      SceVshBridge_stub
                      SceHid_stub
                      SceMotion_stub
                      SceAppUtil_stub
                      SceAvPlayer_stub
                      SDL_mixer
	SDL_ttf
	SDL_image
	SDL
  #ffmpeg
  #libIMGEGL_stub
  #Boost
  avcodec
  avdevice
  avfilter
  avformat
  avutil
  swresample
  swscale
  mp3lame
)



## Create Vita files
#vita_create_self(${PROJECT_NAME}.self ${PROJECT_NAME})
vita_create_self(eboot.bin ${PROJECT_NAME}.elf UNSAFE NOASLR)
# The FILE directive lets you add additional files to the VPK, the syntax is
# FILE src_path dst_path_in_vpk. In this case, we add the LiveArea paths.
vita_create_vpk(${PROJECT_NAME}.vpk ${VITA_TITLEID} eboot.bin
  VERSION ${VITA_VERSION}
  NAME ${VITA_APP_NAME}
  FILE cursor.bmp cursor.bmp
  FILE start.swf start.swf
  FILE sce_sys/icon0.png sce_sys/icon0.png
  FILE sce_sys/livearea/contents/bg.png sce_sys/livearea/contents/bg.png
  FILE sce_sys/livearea/contents/startup.png sce_sys/livearea/contents/startup.png
  FILE sce_sys/livearea/contents/template.xml sce_sys/livearea/contents/template.xml
)
